#!/usr/bin/env python
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
#from matplotlib.backends.backend_qt4 import FigureCanvasQT as FigureCanvas
from matplotlib.backends.backend_qt4 import NavigationToolbar2QT as NavigationToolbar
from matplotlib.backend_bases import NavigationToolbar2

from matplotlib.figure import Figure

import numpy as N

class MyMplCanvas(FigureCanvas):
	def __init__(self, parent=None, width = 1, height = 0.5, dpi = 100, sharex = None, sharey = None):
		self.fig = Figure(figsize = (width, height), dpi=dpi, facecolor = '#FFFFFF')
		self.ax = self.fig.add_subplot(111, sharex = sharex, sharey = sharey)
		self.fig.subplots_adjust(left=0.03, bottom=0.03, right=0.97, top=0.97)
		self.xtitle="x-Axis"
		self.ytitle="y-Axis"
		self.PlotTitle = "Subplot"
		self.grid_status = True
		self.xaxis_style = 'linear'
		self.yaxis_style = 'linear'
		
		self.format_labels()

		self.ax.hold(False)
		FigureCanvas.__init__(self, self.fig)
		FigureCanvas.setSizePolicy(self,
					   QSizePolicy.Expanding,
					   QSizePolicy.Expanding)
		FigureCanvas.updateGeometry(self)

	def update_plot(self):
		self.ax.autoscale_view(tight = False, scalex=True, scaley=True)
		self.format_labels()
		self.fig.subplots_adjust(left=0.03, bottom=0.03, right=0.97, top=0.97)
		self.draw()

	def format_labels(self):
		self.ax.set_xlabel('')
		self.ax.set_ylabel('')
		self.ax.set_xticklabels([])
		self.ax.set_yticklabels([])

	def sizeHint(self):
		w, h = self.get_width_height()
		return QSize(w, h)

	def minimumSizeHint(self):
		return QSize(10, 10)

	def sizeHint(self):
		w, h = self.get_width_height()
		return QSize(w, h)

	def minimumSizeHint(self):
		return QSize(10, 10)


class MPL_Preview_Widget(QWidget):
	def __init__(self, parent = None):
		QWidget.__init__(self, parent)
		self.canvas = MyMplCanvas()
		self.hbox = QHBoxLayout()
		self.hbox.addWidget(self.canvas)
		self.setLayout(self.hbox)
